//
//  WebDetailViewController.m
//  UGoods
//
//  Created by dllo on 16/1/18.
//  Copyright © 2016年 蓝鸥科技.李贺. All rights reserved.
//

#import "WebDetailViewController.h"
#import <WebKit/WebKit.h>
#import "FindModel.h"
#import <MBProgressHUD.h>

@interface WebDetailViewController ()<WKNavigationDelegate>

@property (nonatomic, strong) WKWebView *webView;
@property (nonatomic, retain) MBProgressHUD *HUD;

@end

@implementation WebDetailViewController

- (void)dealloc
{
    [_webView release];
    [_HUD release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
    _webView.navigationDelegate = self;
    [self.view addSubview:_webView];
    [_webView release];
    [self handleHUD];
}

- (void)handleHUD {
    // 1. 创建对象
    self.HUD = [[MBProgressHUD alloc] initWithView:self.view];
    // 2. 添加到当前视图中
    [self.view addSubview:self.HUD];
    // 如果设置此属性, 则置后当前的View
    self.HUD.dimBackground = NO;
    // 设置模式
    self.HUD.mode = MBProgressHUDModeIndeterminate;
    self.HUD.color = [UIColor colorWithWhite:0.800 alpha:1.000];
    [self.HUD show:YES];
    [_HUD release];
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
    [self.HUD hide:YES];
}

- (void)setModel:(FindModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    // webView加载网址
     [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_model.link_url]]];
    NSLog(@"%@", _model.link_url);
    self.navigationItem.title = model.descript;
    self.title = model.title;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
